import Vue from 'vue'
import VueRouter from 'vue-router'
// import Login from "../components/Login.vue"
const Login = () =>
    import ( /* webpackChunkName: "login_home_welcome"*/ "../components/Login.vue")

// import Home from "../components/Home.vue"
const Home = () =>
    import ( /* webpackChunkName: "login_home_welcome"*/ "../components/Home.vue")

// import Welcome from "../components/Welcome.vue"
const Welcome = () =>
    import ( /* webpackChunkName: "login_home_welcome"*/ "../components/Welcome.vue")

// import Users from"../components/user/Uses.vue"
const Users = () =>
    import ( /* webpackChunkName: "Users_Rights_Roles"*/ "../components/user/Uses.vue")

// import Rights from "../components/power/Rights";
const Rights = () =>
    import ( /* webpackChunkName: "Users_Rights_Roles"*/ "../components/power/Rights.vue")

// import Roles from "../components/power/Roles";
const Roles = () =>
    import ( /* webpackChunkName: "Users_Rights_Roles"*/ "../components/power/Roles.vue")


// import Category from "../components/goods/Category";
const Category = () =>
    import ( /* webpackChunkName: "Category_Params"*/ "../components/goods/Category.vue")

// import Params from "../components/goods/Params";
const Params = () =>
    import ( /* webpackChunkName: "Category_Params"*/ "../components/goods/Params.vue")


// import GoodsList from "../components/goods/List";
const GoodsList = () =>
    import ( /* webpackChunkName: "GoodsList_GoodsAdd"*/ "../components/goods/List.vue")

// import GoodsAdd from "../components/goods/GoodsAdd";
const GoodsAdd = () =>
    import ( /* webpackChunkName: "GoodsList_GoodsAdd"*/ "../components/goods/GoodsAdd")

// import Order from "../components/order/Order";
const Order = () =>
    import ( /* webpackChunkName: "Order_Report"*/ "../components/order/Order")

// import Report from "../components/report/Report";
const Report = () =>
    import ( /* webpackChunkName: "Order_Report"*/ "../components/report/Report")

Vue.use(VueRouter)

const routes = [{
    path: "/",
    redirect: "/login"
}, {
    path: "/login",
    name: "login",
    component: Login
}, {
    path: "/home",
    name: "home",
    component: Home,
    redirect: "/welcome",
    children: [{
        path: "/welcome",
        name: "welcome",
        component: Welcome
    }, {
        path: "/users",
        name: "users",
        component: Users
    }, {
        path: "/rights",
        name: "rights",
        component: Rights
    }, {
        path: "/roles",
        name: "roles",
        component: Roles
    }, {
        path: "/categories",
        nane: "categories",
        component: Category
    }, {
        path: "/params",
        name: "params",
        component: Params
    }, {
        path: "/goods",
        name: "goods",
        component: GoodsList,
    }, {
        path: "/goods/add",
        name: "GoodsAdd",
        component: GoodsAdd
    }, {
        path: "/orders",
        name: "order",
        component: Order
    }, {
        path: "/reports",
        name: "reports",
        component: Report
    }]
}]

const router = new VueRouter({
    mode: 'hash',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    if (to.path == "/login") {
        next()
    } else {
        if (sessionStorage.getItem("token")) {
            next()
        } else {
            next("/login")
        }
    }
})

export default router